package cn.lyjuan.android.demofive.ui.tab.tabhost4;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
import cn.lyjuan.android.demofive.R;
import cn.lyjuan.android.demofive.ui.tab.tabhost.FirstTabActivity;
import cn.lyjuan.android.demofive.ui.tab.tabhost.SecondTabActivity;

/**
 * Created by chad on 2016/3/4.
 */
public class TabHostActivity extends TabActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        this.setContentView(R.layout.ui_tabhost4);

        final TabHost th = this.getTabHost();

        TabHost.TabSpec spec = null;
        Intent intent = null;

        intent = new Intent(this, FirstTabActivity.class);
        spec = th.newTabSpec("First1").setIndicator("First2").setContent(intent);
        th.addTab(spec);

        intent = new Intent(this, SecondTabActivity.class);
        spec = th.newTabSpec("Second1").setIndicator("Second2").setContent(intent);
        th.addTab(spec);

        th.setCurrentTab(0);

        RadioGroup rg = (RadioGroup) this.findViewById(R.id.ui_tabhost4_group);
        rg.check(R.id.ui_tabhost4_first);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                switch (checkedId)
                {
                    case R.id.ui_tabhost4_first :
                        th.setCurrentTabByTag("First1");
                        break;
                    case R.id.ui_tabhost4_second :
                        th.setCurrentTabByTag("Second1");
                        break;
                    default :
                        break;
                }
            }
        });

    }
}
